<!doctype html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/general.css"/>
		<style type="text/css">
			*{
				font-size: 0.9em;
			}
			.main{
				width: 100%;
				height: calc(100vh - 44px);
				background-color: white;
				padding: 0.5em;
			}
			.bdiv{
				border: 1px solid #C7C7C7;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				height: 48px;
				border-radius: 10px;
				margin: 1em 0;
			}
			.bdiv>div{
				width: 25%;
				border-right: 1px solid #C7C7C7;
				height: 80%;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.bdiv>input{
				width: 50%;
				border: 0;
				height: 44px;
				margin-bottom: 0px;
				padding: 10px 15px;
			}
			.dimg{
				width: 100%;
				text-align: center;
				padding: 2em;
			}
			.dimg>img{
				width: 35%;
				border-radius: 50%;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <h1 class="mui-title colorw">登录</h1>
		</header>
		<div class="mui-content">
		    <div class="main">
		    	<div class="dimg">
		    		<img src="img/logo.png"/>
		    	</div>
		    	<div class="bdiv mui-input-row">
		    	    <div>手机号码</div>
		    	    <input type="number" id='account' class="mui-input-clear" placeholder="请输入账号">
		    	</div>
		    	<div class="bdiv mui-input-row">
		    	    <div>密码</div>
		    	    <input id='password' type="password" class="mui-input-clear" placeholder="请输入密码">
		    	</div>
		    	<div class="mui-content-padded">
					<button id='login' class="mui-btn mui-btn-block mui-btn-primary hbg">登录</button>
					<div class="link-area"><a id='reg'>注册账号</a> <span class="spliter">|</span> <a id='forgetPassword'>忘记密码</a>
					</div>
				</div>
		    </div>
		</div>
		<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/req.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<!--
        	作者：592176224@qq.com
        	时间：2019-05-05
        	描述：
        	<script src="js/app.js"></script>
        -->
		
		<script type="text/javascript">
			(function($, doc) {
					//var settings = app.getSettings();
					//var state = app.getState();
					var toMain = function(is_show,numbers) {
						//$.fire(mainPage, 'show', null);
						//setTimeout(function() {
							//console.log(is_show)
							//console.log(numbers)
							//return;
							mui.openWindow({
							    url: 'index.html?is_show='+is_show+'&numbers='+parseInt(numbers),
							    id: 'idnex'
							 });
						//}, 0);
					};
					var to_message = function(is_show) {
						//$.fire(mainPage, 'show', null);
						//setTimeout(function() {
							mui.openWindow({
							    url: 'personal/reception.html?is_show='+is_show,
							    id: 'reception'
							});
						//}, 0);
					};
					
					//检查 "登录状态" 结束
					var loginButton = doc.getElementById('login');
					var accountBox = doc.getElementById('account');
					var passwordBox = doc.getElementById('password');
					var autoLoginButton = doc.getElementById("autoLogin");
					var regButton = doc.getElementById('reg');
					var forgetButton = doc.getElementById('forgetPassword');
					if(localStorage.getItem("phone")){
						var phone = localStorage.getItem("phone");
						var psword = localStorage.getItem("psword");
						accountBox.value = phone;
						passwordBox.value = psword;
					}
					loginButton.addEventListener('tap', function(event) {
						var loginInfo = {
							url:"/api/login",
							data:{
								phone: accountBox.value,
								password: passwordBox.value
							}
						};
						console.log("开始登陆！");
						ajax(loginInfo, function(res) {
							console.log("登陆数据",res);
							localStorage.setItem("accesstoken",res.data.access_token);
							localStorage.setItem("username",res.data.employee.username);
							localStorage.setItem("phone",loginInfo.data.phone);
							localStorage.setItem("psword",loginInfo.data.password);
							console.log("accesstoken",res.data.access_token);
							console.log("公司名称",res.data.employee.username);
							mui.toast("登陆成功！");
							//toMain();
							if(res.data.employee.store.is_formal == 1){
								console.log("is_formal")
								if(res.data.employee.store.diffdate > 15){
									toMain();
								}else if(res.data.employee.store.diffdate <= 15 && res.data.employee.store.diffdate >= 0){
									toMain(true,res.data.employee.store.diffdate);
								}else{
									to_message(true);
								}
							}else{
								if(res.data.employee.store.diffdate < 0){
									to_message(true);
								}else{
									toMain();
								}
							}
						});
						
					});
					regButton.addEventListener('tap', function(event) {
						$.openWindow({
							url: 'register.html',
							id: 'register',
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
					}, false);
					forgetButton.addEventListener('tap', function(event) {
						$.openWindow({
							url: 'getpassword.html',
							id: 'getpassword',
							preload: true,
							show: {
								aniShow: 'pop-in'
							},
							styles: {
								popGesture: 'hide'
							},
							waiting: {
								autoShow: false
							}
						});
					}, false);
					var backButtonPress = 0;
					$.back = function(event) {
						backButtonPress++;
						if (backButtonPress > 1) {
							plus.runtime.quit();
						} else {
							plus.nativeUI.toast('再按一次退出应用');
						}
						setTimeout(function() {
							backButtonPress = 0;
						}, 1000);
						return false;
					};
			}(mui, document));
		</script>
	</body>

</html>